import java.util.Locale;

public class demo {
    public static void main1(String[] args) {
        String d ="sadsd";
        String c = new String("sad");
        String a = d;//a/d指向的是同一个对象
        System.out.println(a.length());

        String b ="";
        System.out.println(b);//长度为0
        String v = null;
        System.out.println(b.isEmpty());//返回true,是空的但是和null不同,他有指向
        //System.out.println(v.isEmpty());//空指针异常

        String s1 = "A";
        String s2 = "a";
        System.out.println(a.equals(b));//比较大小
        System.out.println(s1.equals(s2));
    }

    public static void main2(String[] args) {
        String s1 = new String("hello");

        char ch1 = s1.charAt(2);//不能越界
        System.out.println(ch1);

        int index = s1.indexOf("e");//也可以查找字符串
        int index2  =s1.indexOf("llo");
        System.out.println(index);//返回字符位置,重复时,返回第一个的位置(从头开始查找)
        System.out.println(index2);
    }

    public static void main3(String[] args) {
        //整数转化成字符串
        String s1 = String.valueOf(234);
        System.out.println(s1);

        //字符串转化成整数
        int a = Integer.parseInt("234");//使用包装类

        //大小写转换
        String s2 = "hello";
        String s3 = "HELLO";
        String s4 = s2.toUpperCase(Locale.ROOT);//变成大写
        System.out.println(s4);
        String s5  =s3.toLowerCase(Locale.ROOT);//变成小写
        System.out.println(s5);

    }

    public static void main4(String[] args) {
        String s1 = new String("qwertyyui");
        String ret = s1.replace("y","c");//只要是要替换的,不管数量多少,全部替换(从头开始)
        System.out.println(s1);
        System.out.println(ret);

        String ret1 =s1.replaceFirst("y","g");//只换找到的第一个
        System.out.println(ret1);
    }

    public static void main5(String[] args) {
        String str = new String("qwqwqwqwqw");
        String[] str2 = str.split("q");
        for (int i = 0; i < str2.length; i++) {
            System.out.println(str2[i]);
        }
    }

    public static void main6(String[] args) {
        String str = new String("qwertyuiop");
        String str2 = str.substring(3);
        System.out.println(str2);

        String str3 = str.substring(3,6);
        System.out.println(str3);
    }

    public static void main7(String[] args) {
        StringBuilder stringBuilder = new StringBuilder("111");
        System.out.println(stringBuilder);

        StringBuffer stringBuffer = new StringBuffer();
        String a ="344";
        a = "weqw";
        System.out.println(a);
    }


    public static void main8(String[] args) {
        String s = "asdefaef";
        int[] count = new int[26];
        int flag = 0;
        for (int i = 0; i <s.length() ; i++) {
            char ch = s.charAt(i);
            count[ch-'a']++;
        }
    }

    public static void main(String[] args) {
        String str = new String(" hello world ");// hello world 左右都有空格
        System.out.println("["+str+"]");
        System.out.println("["+str.trim()+"]");//hello world左右没有空格
    }

}






















